package com.fulihui.wgj.dal.mybatis.repository;

import com.fulihui.wgj.dal.mybatis.domain.WxQrcodeReplyInfo;
import com.fulihui.wgj.dal.mybatis.mapper.WxQrcodeReplyInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author wang_wx
 * @date 2018-06-20
 */
@Component
public class WxQrcodeReplyInfoRepository extends BaseRepository<WxQrcodeReplyInfo> {

    @Resource
    WxQrcodeReplyInfoMapper wxQrcodeReplyInfoMapper;

    /**
     * 根据AppIdAndSceneStr更新
     *
     * @param qrcodeReplyInfo
     * @return
     */
    public Integer updateByAppIdAndSceneStr(WxQrcodeReplyInfo qrcodeReplyInfo) {
        qrcodeReplyInfo.setGmtModified(new Date());
        return wxQrcodeReplyInfoMapper.updateByExampleSelective(qrcodeReplyInfo, buildExample(qrcodeReplyInfo));
    }

    Example buildExample(WxQrcodeReplyInfo qrcodeReplyInfo) {
        Example example = new Example(WxQrcodeReplyInfo.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(qrcodeReplyInfo.getAppId())) {
            criteria.andEqualTo("appId", qrcodeReplyInfo.getAppId());
        }
        if (StringUtils.isNotBlank(qrcodeReplyInfo.getAppId())) {
            criteria.andEqualTo("sceneStr", qrcodeReplyInfo.getSceneStr());
        }
        return example;
    }

    /**
     * 根据AppIdAndSceneStr删除
     *
     * @param qrcodeReplyInfo
     * @return
     */
    public Integer deleteByAppIdAndSceneStr(WxQrcodeReplyInfo qrcodeReplyInfo) {
        return wxQrcodeReplyInfoMapper.deleteByExample(buildExample(qrcodeReplyInfo));
    }
}
